/**
 * prechoose
 */
package com.thinkgem.jeesite.zmis.prechoose.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.zmis.prechoose.entity.ZmisPrechoose;
import com.thinkgem.jeesite.zmis.prechoose.service.ZmisPrechooseService;

/**
 * 预选表Controller
 * @author ll
 * @version 2017-10-12
 */
@Controller
@RequestMapping(value = "${adminPath}/prechoose/zmisPrechoose")
public class ZmisPrechooseController extends BaseController {

	@Autowired
	private ZmisPrechooseService zmisPrechooseService;
	
	@ModelAttribute
	public ZmisPrechoose get(@RequestParam(required=false) String id) {
		ZmisPrechoose entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zmisPrechooseService.get(id);
		}
		if (entity == null){
			entity = new ZmisPrechoose();
		}
		return entity;
	}
	
	@RequiresPermissions("prechoose:zmisPrechoose:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZmisPrechoose zmisPrechoose, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZmisPrechoose> page = zmisPrechooseService.findPage(new Page<ZmisPrechoose>(request, response), zmisPrechoose); 
		model.addAttribute("page", page);
		return "zmis/prechoose/zmisPrechooseList";
	}

	@RequiresPermissions("prechoose:zmisPrechoose:view")
	@RequestMapping(value = "form")
	public String form(ZmisPrechoose zmisPrechoose, Model model) {
		model.addAttribute("zmisPrechoose", zmisPrechoose);
		return "zmis/prechoose/zmisPrechooseForm";
	}

	@RequiresPermissions("prechoose:zmisPrechoose:edit")
	@RequestMapping(value = "save")
	public String save(ZmisPrechoose zmisPrechoose, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zmisPrechoose)){
			return form(zmisPrechoose, model);
		}
		zmisPrechooseService.save(zmisPrechoose);
		addMessage(redirectAttributes, "保存选择成功");
		return "redirect:"+Global.getAdminPath()+"/prechoose/zmisPrechoose/?repage";
	}
	
	@RequiresPermissions("prechoose:zmisPrechoose:edit")
	@RequestMapping(value = "delete")
	public String delete(ZmisPrechoose zmisPrechoose, RedirectAttributes redirectAttributes) {
		zmisPrechooseService.delete(zmisPrechoose);
		addMessage(redirectAttributes, "删除选择成功");
		return "redirect:"+Global.getAdminPath()+"/prechoose/zmisPrechoose/?repage";
	}

}